/*
 * FeatureLine.cpp
 *
 *  Created on: May 4, 2009
 *      Author: wrice
 */
#include "MyVideoTrace.h"
namespace MyVideoTrace {


FeatureLine::FeatureLine( FeaturePoint * lineFrom, FeaturePoint * lineTo)
: lineFrom_(lineFrom)
, lineTo_(lineTo)
{
}

FeaturePoint * FeatureLine::getLineFrom() const {
	return lineFrom_;
}

FeaturePoint * FeatureLine::getLineTo() const {
	return lineTo_;
}

bool FeatureLine::isTriangle( FeatureLine line1, FeatureLine line2, FeatureLine line3 ) {
	set< FeaturePoint * > set1, set2, set3, set4;

	set1.insert( line1.getLineFrom() );
	set1.insert( line1.getLineTo() );
	set1.insert( line2.getLineFrom() );
	set1.insert( line2.getLineTo() );
	if( set1.size() != 3 ) return false;

	set2.insert( line1.getLineFrom() );
	set2.insert( line1.getLineTo() );
	set2.insert( line3.getLineFrom() );
	set2.insert( line3.getLineTo() );
	if( set2.size() != 3 ) return false;

	set3.insert( line2.getLineFrom() );
	set3.insert( line2.getLineTo() );
	set3.insert( line3.getLineFrom() );
	set3.insert( line3.getLineTo() );
	if( set3.size() != 3 ) return false;

	set3.insert( line1.getLineFrom() );
	set3.insert( line1.getLineTo() );
	if( set3.size() != 3 ) return false;

	return true;
}

FeaturePoint * FeatureLine::getSharedPoint( FeatureLine line1, FeatureLine line2 ) {
	if( line1.getLineFrom() == line2.getLineFrom() ) return line1.getLineFrom();
	if( line1.getLineFrom() == line2.getLineTo() ) return line1.getLineFrom();
	if( line1.getLineTo() == line2.getLineFrom() ) return line1.getLineTo();
	if( line1.getLineTo() == line2.getLineTo() ) return line1.getLineTo();
	return NULL;
}


}
